import { RequestHandler } from 'express'
import { failure, success } from '@/utils/response'
import attachmentService from '@/services/attachmentService'

const getAttachments: RequestHandler = async (req, res) => {
  try {
    const data = await attachmentService.getAttachments(req.query)
    success(res, '查询附件列表成功。', data)
  } catch (error) {
    failure(res, error as Error, '查询附件列表失败：')
  }
}

const deleteAttachment: RequestHandler = async (req, res) => {
  try {
    await attachmentService.deleteAttachment(+req.params.id)
    success(res, '删除附件成功。')
  } catch (error) {
    failure(res, error as Error, '删除附件失败：')
  }
}

export default {
  getAttachments,
  deleteAttachment,
}
